package com.ruoyi.web.controller.biz;

import java.util.List;

import com.ruoyi.biz.domain.RepairRecord;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.biz.service.IRepairRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2020-11-30
 */
@RestController
@RequestMapping("/system/repair/record")
public class RepairRecordController extends BaseController
{
    @Autowired
    private IRepairRecordService repairRecordService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('operate:repair:list')")
    @GetMapping("/list")
    @ApiOperation("查询维修记录列表")
    public TableDataInfo list(RepairRecord repairRecord)
    {
        startPage();
        List<RepairRecord> list = repairRecordService.selectRepairRecordList(repairRecord);
        return getDataTable(list);
    }

    @GetMapping("/repairName")
    public List<RepairRecord> getRepairName(){
        return repairRecordService.selectRepairRecordList(new RepairRecord());
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('operate:repair:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出维修记录信息")
    public AjaxResult export(RepairRecord repairRecord)
    {
        List<RepairRecord> list = repairRecordService.selectRepairRecordList(repairRecord);
        ExcelUtil<RepairRecord> util = new ExcelUtil<RepairRecord>(RepairRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('operate:repair:query')")
    @GetMapping(value = "/{repairId}")
    @ApiOperation("获取维修记录信息")
    public AjaxResult getInfo(@PathVariable("repairId") Long repairId)
    {
        return AjaxResult.success(repairRecordService.selectRepairRecordById(repairId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('operate:repair:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增维修记录信息")
    public AjaxResult add(@RequestBody RepairRecord repairRecord)
    {
        return toAjax(repairRecordService.insertRepairRecord(repairRecord));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('operate:repair:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改维修记录信息")
    public AjaxResult edit(@RequestBody RepairRecord repairRecord)
    {
        return toAjax(repairRecordService.updateRepairRecord(repairRecord));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('operate:repair:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{repairIds}")
    @ApiOperation("批量删除维修记录信息")
    public AjaxResult remove(@PathVariable Long[] repairIds)
    {
        return toAjax(repairRecordService.deleteRepairRecordByIds(repairIds));
    }

    /**
     * 设置设备的维修状态
     */
    @PreAuthorize("@ss.hasPermi('operate:repair:edit')")
    @PostMapping("/updateStatus")
    @ApiOperation("修改维修记录状态")
    public AjaxResult updateRepairStatus(@RequestBody RepairRecord repairRecord) {
        return toAjax(repairRecordService.updateRepairStatus(repairRecord));
    }
}
